//
//  SideTableViewCell.m
//  fitnessmanage
//
//  Created by wujian on 2017/10/29.
//  Copyright © 2017年 zongquankeji. All rights reserved.
// 体侧TableViewCell

#import "SideTableViewCell.h"

@implementation SideTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor = CSClearColor;
        
        UIView *whiteBgView = [[UIView alloc] init];
        whiteBgView.backgroundColor = CSWhiteColor;
        [self.contentView addSubview:whiteBgView];
        self.whiteBgView = whiteBgView;
        
        UIView *titleLineView = [[UIView alloc] init];
        titleLineView.backgroundColor = ButtonBackGroundColor;
        [self.contentView addSubview:titleLineView];
        self.titleLineView = titleLineView;
        
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.font = TitleBoldFont;
        titleLabel.text = @"基础体侧数据";
        [whiteBgView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = LineBackGroundColor;
        [whiteBgView addSubview:lineView];
        self.lineView = lineView;
        
        UILabel *detailLabel = [[UILabel alloc] init];
        detailLabel.font = MidFont;
        detailLabel.text = @"创  建  人：涨粉啦";
        detailLabel.textColor = CSColorFromRGB(0x7a7a7a);
        [whiteBgView addSubview:detailLabel];
        self.detailLabel = detailLabel;
        
        
        UILabel *bottomLabel = [[UILabel alloc] init];
        bottomLabel.font = MidFont;
        bottomLabel.text = @"创建时间：2017-12-10";
        bottomLabel.textColor = CSColorFromRGB(0x7a7a7a);
        [whiteBgView addSubview:bottomLabel];
        self.bottomLabel = bottomLabel;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.whiteBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.bottom.mas_equalTo(self.contentView);
        
        make.left.mas_equalTo(self.contentView).offset(10);
        
        make.right.mas_equalTo(self.contentView).offset(-10);
    }];
    
    [self.titleLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.titleLabel);
        
        make.left.mas_equalTo(self.whiteBgView).offset(15);
        
        make.width.mas_equalTo(3);
        
        make.height.mas_equalTo(self.titleLabel);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.titleLineView.mas_right).offset(10);
        
        make.top.mas_equalTo(self.whiteBgView).offset(20);
        
        make.right.mas_equalTo(self.whiteBgView).offset(-10);
    }];
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(15);
        
        make.left.mas_equalTo(self.titleLineView);
        
        make.right.mas_equalTo(self.whiteBgView).offset(-10);
        
        make.height.mas_equalTo(1);
    }];
    
    [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.titleLineView);
        
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(15);
        
        make.right.mas_equalTo(self.whiteBgView).offset(-10);
    }];

    [self.bottomLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.detailLabel);
        
        make.top.mas_equalTo(self.detailLabel.mas_bottom).offset(10);
        
        make.bottom.mas_equalTo(self.whiteBgView).offset(-10);
        
        make.right.mas_equalTo(self.whiteBgView).offset(-10);
    }];
}

-(void)layoutSubviews{
    
    //[self drawDashLine:self.lineView lineLength:10 lineSpacing:5 lineColor:CSRedColor];
}

- (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor
{
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:lineView.bounds];
    [shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
    [shapeLayer setFillColor:[UIColor clearColor].CGColor];
    
    //  设置虚线颜色为
    [shapeLayer setStrokeColor:lineColor.CGColor];
    
    //  设置虚线宽度
    [shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
    [shapeLayer setLineJoin:kCALineJoinRound];
    
    //  设置线宽，线间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
    
    //  设置路径
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0);
    
    [shapeLayer setPath:path];
    CGPathRelease(path);
    
    //  把绘制好的虚线添加上来
    [lineView.layer addSublayer:shapeLayer];
}

@end
